#coding=utf-8
import os,datetime
from stutils import *
from stvalidator import *
from stscraper import price_head
set_django_environ()
from stdj.stock.models import *
from django.db import connection

from stsettings import datadir
HISTPRICEDIR = datadir + '/histprice'

'''
目的:撤销用everyday.py脚本对csv文件,db的数据导入.
'''

td = datetime.date.today().isoformat()

#csv file
ns = os.listdir(HISTPRICEDIR)
ns.sort()
for n in ns:
    fn = HISTPRICEDIR + '/' + n
    data = csv2data( fn )
    d = data[-1]
    if d[0] == td:
        data = data[:-1]
        data2csv(data, price_head, fn)
        print n
        
#db price 
for s in Share.objects.order_by('code'):
    e = s.exday_today()
    if not e:
        continue
    p = e.price
    if p:
        p.delete()
        print e
#db exday
connection.cursor().execute('delete from stock_exday where date = %s', (td,))
